<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">  <!-- Use Chrome Frame in IE -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="description" content="Construct polygons from a set of points, an rectangle, or a nested hierarchy and apply materials to them.">
    <meta name="cesium-sandcastle-labels" content="Showcases">
    <title>Cesium Demo</title>
    <script type="text/javascript" src="../Sandcastle-header.js"></script>
    <script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/require.js"></script>
    <script type="text/javascript">
    require.config({
        baseUrl : '../../../Source',
        waitSeconds : 60
    });
    </script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
    @import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
    "use strict";
//Sandcastle_Begin
function createPrimitives(scene) {
    // Create a simple polygon
    var polygon = scene.primitives.add(new Cesium.Polygon({
        positions : Cesium.Cartesian3.fromDegreesArray([
             -72.0, 40.0,
             -70.0, 35.0,
             -75.0, 30.0,
             -70.0, 30.0,
             -68.0, 40.0])
    }));
    Sandcastle.declare(polygon);    // For highlighting on mouseover in Sandcastle.
    
    polygon = scene.primitives.add(new Cesium.RectanglePrimitive({
        rectangle : Cesium.Rectangle.fromDegrees(-110.0, 0.0, -90.0, 20.0),
        rotation : Cesium.Math.toRadians(45),
        material : Cesium.Material.fromType(Cesium.Material.ColorType, {
            color : new Cesium.Color(1.0, 0.0, 1.0, 0.75)
        })
    }));
    Sandcastle.declare(polygon);

    // Create a nested polygon with holes
    var hierarchy = {
        positions : Cesium.Cartesian3.fromDegreesArray([
             -109.0, 30.0,
             -95.0, 30.0,
             -95.0, 40.0,
             -109.0, 40.0
         ]),
         holes : [{
             positions : Cesium.Cartesian3.fromDegreesArray([
                 -107.0, 31.0,
                 -107.0, 39.0,
                 -97.0, 39.0,
                 -97.0, 31.0
             ]),
             holes : [{
                 positions : Cesium.Cartesian3.fromDegreesArray([
                     -105.0, 33.0,
                     -99.0, 33.0,
                     -99.0, 37.0,
                     -105.0, 37.0
                 ]),
                 holes : [{
                     positions : Cesium.Cartesian3.fromDegreesArray([
                         -103.0, 34.0,
                         -101.0, 34.0,
                         -101.0, 36.0,
                         -103.0, 36.0
                     ])
                }]
            }]
        }]
    };
    var polygonHierarchy = scene.primitives.add(new Cesium.Polygon({
        polygonHierarchy : hierarchy,
        material : Cesium.Material.fromType('Color', {
            color : new Cesium.Color(0.0, 1.0, 1.0, 0.75)
        })
    }));
    Sandcastle.declare(polygonHierarchy);   // For highlighting on mouseover in Sandcastle.

    // Create a polygon from an rectangle
    var polygonRectangle = scene.primitives.add(new Cesium.RectanglePrimitive({
        rectangle : Cesium.Rectangle.fromDegrees(-180.0, 50.0, 180.0, 90.0)
    }));
    Sandcastle.declare(polygonRectangle);  // For highlighting on mouseover in Sandcastle.

    // Apply a material to a polygon
    var checkeredPolygon = scene.primitives.add(new Cesium.Polygon({
        positions : Cesium.Cartesian3.fromDegreesArray([
            -90.0, 30.0,
            -80.0, 30.0,
            -80.0, 40.0,
            -90.0, 40.0
        ]),
        material : Cesium.Material.fromType('Checkerboard')
    }));
    Sandcastle.declare(checkeredPolygon);   // For highlighting on mouseover in Sandcastle.
}

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.screenSpaceEventHandler.setInputAction(function(movement) {
    var pickedPrimitive = viewer.scene.pick(movement.endPosition);
    Sandcastle.highlight(pickedPrimitive);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

createPrimitives(viewer.scene);
//Sandcastle_End
    Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
    startup(Cesium);
} else if (typeof require === "function") {
    require(["Cesium"], startup);
}
</script>
</body>
</html>
